package com.fenghongzhang.day003;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Notification;
import android.app.NotificationManager;
import android.os.Bundle;
import android.view.View;

import java.util.Timer;
import java.util.TimerTask;

public class Main3Activity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);
    }

    public void sendPro(View view) {

        final NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        final Notification.Builder builder = new Notification.Builder(this);
        builder.setSmallIcon(R.mipmap.ic_launcher).setContentTitle("进度条");
        builder.setContentTitle("正在下载..");

        //进度
        /**
         * 1最大值,
         * 2,进度值
         * 3,是否模糊
         */
//        builder.setProgress(100,50,true);

        final Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            int progress = 0;
            @Override
            public void run() {
                builder.setProgress(100,progress,false);
                progress+= 10;
                manager.notify(2,builder.build());

                //到最大值以后.
                if(progress >= 100){
                    builder.setProgress(0,0,true);
                    builder.setContentText("正在安装");
                    manager.notify(2,builder.build());

                    try {
                        Thread.sleep(5000); //
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    timer.cancel();
                    manager.cancel(2);
                }

            }
        },0,1000);



        manager.notify(2,builder.build());
    }
}
